/*
 * Copyright (C) 2014 luke.
 * 
 * This file is part of Silvie.
 * 
 * Silvie is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Silvie is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Silvie.  If not, see <http://www.gnu.org/licenses/>.
 */

package silvie.resources.sprite;

import java.awt.Image;

import utils.PalettizedImage;

/**
 * Abstract class containing all attributes and methods that are shared across
 * sprite types.
 * 
 * @author luke
 */
public abstract class AbstractSprite {
	public static final int SPR_TRANSPARENT_INDEX = 0;
	protected int dataSize;
	protected byte[] spriteData;
	protected PalettizedImage palettizedImage;

	/**
	 * AbstractSprite constructor.
	 * 
	 * @param spritePalette the palette to use.
	 * @param dataSize the sprite's data size (as read from the sprite container
	 *        description).
	 * @param width the sprite width.
	 * @param height the sprite height.
	 */
	public AbstractSprite(byte[] spritePalette, int dataSize, int width, int height) {
		this.dataSize = dataSize;
		this.spriteData = null;
		this.palettizedImage = new PalettizedImage(width, height, spritePalette);
	}

	/**
	 * Decodes this sprite's data to get the pixel indices.
	 */
	public abstract void decode();

	/**
	 * Creates and returns an Image for the sprite.
	 * 
	 * @return an Image for this sprite.
	 */
	public Image createImage() {
		return this.palettizedImage.createImage();
	}

	public int getWidth() {
		return this.palettizedImage.getWidth();
	}

	public int getHeight() {
		return this.palettizedImage.getHeight();
	}

	public int getSize() {
		return this.dataSize;
	}

	public void setSpriteData(byte[] spriteData) {
		this.spriteData = spriteData;
	}
}
